# -*- coding:utf-8 -*-

# 位运算练习
class Solution:
	def NumberOf1(self, n):
		'''
		return the number of 1 in bin(1)
		'''
		cnt = 0
		
		if n<0:
			# 负数用补码
			n = n & 0xffffFFFF
		
		while n:
			cnt += 1
			n = (n-1) & n
		return cnt

# SyntaxError: invalid syntax
#Solution sl = new Solution()
sl = Solution()
cnt = sl.NumberOf1(0b1101)
print('cnt=', cnt) # 3
cnt = sl.NumberOf1(-1)
print('cnt=', cnt) # 32
